//
//  LZFinancialSummaryViewController.m
//  laziz_Merchant
//
//  Created by xbnzd on 16/12/20.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZFinancialSummaryViewController.h"
#import "LZFinancialRecordsViewController.h"
#import "LZOrderListViewController.h"
#import "LZFinancialPresenter.h"
#import "LZUserModel.h"

@interface LZFinancialSummaryViewController ()
@property (weak, nonatomic) IBOutlet UILabel *totleAmountLabel;//总共金额
@property (weak, nonatomic) IBOutlet UILabel *subTitleLabel;  //子标题
@property (weak, nonatomic) IBOutlet UILabel *alreadyPayedlabel; //已经结账
@property (weak, nonatomic) IBOutlet UILabel *notPayedLabel;   //未结款
@property (strong, nonatomic) LZFinancialPresenter *financialPresenter;
@property (strong, nonatomic) NSDictionary *dataDic;

@end

@implementation LZFinancialSummaryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.umLogPageViewName = @"财务结款摘要页面";
    
    [self configureUIAndData];
    
    [self getFanincalData];
}

#pragma mark -
#pragma mark private
- (void)configureUIAndData
{
    self.title = LZLocalizedString(@"home_menu_financial_records", nil);
    self.subTitleLabel.text = LZLocalizedString(@"total_coupons_amount", nil);
    self.alreadyPayedlabel.layer.cornerRadius = 20.0;
    self.alreadyPayedlabel.layer.masksToBounds = YES;
    self.notPayedLabel.layer.cornerRadius = 20.0;
    self.notPayedLabel.layer.masksToBounds = YES;
    self.notPayedLabel.layer.borderWidth = 0.5;
    self.notPayedLabel.layer.borderColor = UIColorFromRGB(0x33a928, 1).CGColor;
    
    _financialPresenter = [[LZFinancialPresenter alloc] init];
}

- (void)getFanincalData
{
    WS(weakSelf);
   [self.financialPresenter getFinanicalSummaryWithSellerID:[LZUserModel Instance].sellerId resultSuccess:^(id data) {
        weakSelf.dataDic = (NSDictionary *)data;
       
       [weakSelf setContentData];
       
   } Failure:^(NSString *fail) {
       DLog(@"%@",fail);
   }];
}

- (void)setContentData
{
    NSString *bhd = @"BHD";
    NSString *totleMoney = [NSString stringWithFormat:@"%@",self.dataDic[@"totalAmt"]];
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@",totleMoney,bhd]];
    [attStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:30] range:NSMakeRange(0, totleMoney.length)];
    [attStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(totleMoney.length + 1, bhd.length)];
    
    self.totleAmountLabel.attributedText = attStr;
    
    self.alreadyPayedlabel.text = [NSString stringWithFormat:@"%@ BHD %@",self.dataDic[@"settlementAmt"],LZLocalizedString(@"provided_funds", nil)];
    self.notPayedLabel.text = [NSString stringWithFormat:@"%@ BHD %@",self.dataDic[@"unSettlementAmt"],LZLocalizedString(@"funds_yet_to_provide", nil)];
}

//已经结账按钮
- (IBAction)alreadyPayedBtnAction:(id)sender {
    LZFinancialRecordsViewController *vc = [[LZFinancialRecordsViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

//未结账按钮
- (IBAction)notPayedBtnAction:(id)sender {
    LZOrderListViewController *vc = [[LZOrderListViewController alloc] init];
    vc.comeFromFinancialVC = YES;
    vc.onlyGetNonePayedList = YES;
    [self.navigationController pushViewController:vc animated:YES];
}


@end
